using System;

namespace UselessExplorer
{
    public class ClsGlobal
    {
        ucPrefrencesExtension fae = new ucPrefrencesExtension();
        
        private static ClsGlobal instance;
        public static ClsGlobal Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new ClsGlobal();
                }
                return instance;
            }
        }

        private string iconPath;
        private int formLeft;
        private int formTop;

        public int FormLeft
        {
            get { return formLeft; }
            set { formLeft = value; }
        }

        public int FormTop
        {
            get { return formTop; }
            set { formTop = value; }
        }

        public string IconPath
        {
            get { return iconPath; }
            set { iconPath = value; }
        }

        private string[] extensions;
        public string[] Extensions
        {
            get { return extensions; }
            set { extensions = value; }
        }

        public ClsGlobal()
        {
            FormLeft = 20;
            FormTop = 20;
        }

        public enum StatusExtnAdd : int
        {
            ExtensionAdded = 1,
            Restricted,
            Failed
        }

        public void initialiseTrace()
        {
            frmTraces.Instance.WindowState = System.Windows.Forms.FormWindowState.Minimized;
            frmTraces.Instance.Show();
        }

        public void InitialiseTrace(frmTraces fTrace)
        {
            frmTraces.Instance.WindowState = System.Windows.Forms.FormWindowState.Minimized;
            frmTraces.Instance.Show();
        }

        

        public StatusExtnAdd SaveExtensions()
        {
            return fae.SaveConfiguration();
        }

        public bool IsExtensionRestricted(string extension)
        {
            return fae.IsRestricted(extension);
        }

        //public string GetIconName(string fileName)
        //{
        //    string iconName = "genericOrange.ico";

        //    if (fileName.EndsWith(".cs", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "cs.ico";
        //    }
        //    else if (fileName.EndsWith(".cpp", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "cpp.ico";
        //    }
        //    else if (fileName.EndsWith(".zip", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "zip2.ico";
        //    }
        //    else if (fileName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "txt.ico";
        //    }
        //    else if (fileName.EndsWith(".vbs", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "vbs2.ico";
        //    }
        //    else if (fileName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "xml.ico";
        //    }
        //    else if (fileName.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "png.ico";
        //    }
        //    else if (fileName.EndsWith(".php", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "php.ico";
        //    }
        //    else if (fileName.EndsWith(".js", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "js.ico";
        //    }
        //    else if (fileName.EndsWith(".html", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".htm", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "htmlFireFox.ico";
        //    }
        //    else if (fileName.EndsWith(".gif", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "gif.ico";
        //    }
        //    else if (fileName.EndsWith(".ppt", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "ppt.ico";
        //    }
        //    else if (fileName.EndsWith(".rtf", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "rtf.ico";
        //    }
        //    else if (fileName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "exe1.ico";
        //    }
        //    else if (fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "dll.ico";
        //    }
        //    else if (fileName.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "bmp.ico";
        //    }
        //    else if (fileName.EndsWith(".css", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "css.ico";
        //    }
        //    else if (fileName.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "jpg.ico";
        //    }
        //    else if (fileName.EndsWith(".css", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "css.ico";
        //    }
        //    else if (fileName.EndsWith(".db", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".mdb", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "db.ico";
        //    }
        //    else if (fileName.EndsWith(".iso", StringComparison.OrdinalIgnoreCase))
        //    {
        //        iconName = "ISO.ico";
        //    }
        //    else
        //    {
        //        iconName = "genericBlue.ico";
        //    }
        //    return iconName;

        //}

        public int GetIconIndex(string fileName)
        {
            int iconIndex = 22;

            if (fileName.EndsWith(".cs", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 9;
            }
            else if (fileName.EndsWith(".cpp", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 8;
            }
            else if (fileName.EndsWith(".zip", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 61;
            }
            else if (fileName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 54;
            }
            else if (fileName.EndsWith(".vbs", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 56;
            }
            else if (fileName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 60;
            }
            else if (fileName.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 46;
            }
            else if (fileName.EndsWith(".php", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 44;
            }
            else if (fileName.EndsWith(".js", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 37;
            }
            else if (fileName.EndsWith(".html", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".htm", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 31;
            }
            else if (fileName.EndsWith(".gif", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 25;
            }
            else if (fileName.EndsWith(".ppt", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 48;
            }
            else if (fileName.EndsWith(".rtf", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 51;
            }
            else if (fileName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 15;
            }
            else if (fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 12;
            }
            else if (fileName.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 6;
            }
            else if (fileName.EndsWith(".css", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 9;
            }
            else if (fileName.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 36;
            }
            else if (fileName.EndsWith(".db", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".mdb", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 10;
            }
            else if (fileName.EndsWith(".iso", StringComparison.OrdinalIgnoreCase))
            {
                iconIndex = 35;
            }
            else
            {
                iconIndex = 20;
            }
            return iconIndex;

        }


        public void WriteLogs(Logger.LogsCategory LogsCat,Exception ex)
        {
            Logger.Instance.WriteLogs(LogsCat, ex);
        }
    }
}
